<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input type="text" placeholder="enter the name you search" v-model="keywords"/>&nbsp;
      <button @click="searchUsermsg">Search</button>
    </div>
  </section>
</template>

<script>
import axios from 'axios'
// 消息订阅与发布
import pubsub from 'pubsub-js' 

  export default {
    name:'Search',
    data() {
      return {
        keywords:''
      }
    },
    methods:{
      searchUsermsg(){
        // axios是一个promise对象
        axios.get(`https://api.github.com/search/users?q=${this.keywords}`).then(
          response=>{
            // console.log('请求成功');
            // console.log(response.data);
            // this.$bus.$emit('getUserData',response.data.items)
            
            // 第二种消息订阅与发布
            pubsub.publish('getUserData',response.data.items)
          },
          err=>{
            console.log('请求失败');
          })
      }
    }
  }
</script>

<style>

</style>